package com.shop2cn.iapi.sqoptrade.testcase;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

import com.ymttest.business.service.shenqi.*;
import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.shenqisettlement.parameter.bean.AgentProductBean;
import com.shop2cn.iapi.sqoptrade.parameter.enums.CancelOrderTypeEnum;
import com.shop2cn.iapi.sqoptrade.parameter.req.ConfirmApplyRefundReq;
import com.shop2cn.iapi.sqoptrade.resp.Order;
import com.shop2cn.iapi.sqoptrade.resp.TradingServiceResp;
import com.shop2cn.iapi.sqoptrade.service.ConfirmApplyRefundCall;
import com.ymatou.iapi.synctrade.service.TradingSyncService;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.business.service.SQPayGateWayCallService;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.business.service.shenqi.bean.ShenqiUserSet;
import com.ymttest.database.sharding.db.sharding.model.OrderDetailPo;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sharding.model.PaymentPo;
import com.ymttest.database.sharding.db.sharding.model.RefundBillPo;
import com.ymttest.database.sharding.db.sharding.model.UserRefundFundDetailPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.database.sqlwapper.DGUserWapper;

/**
 * 申请退货退款接口 FreeMaker Template自动生成代码
 */
@TestSuite
@Ignore
public class Ts_ConfirmApplyRefund {

	private static ConfirmApplyRefundReq applyRefundReq;
	private static ConfirmApplyRefundCall applySalesRefundCall;

	private static OrderShardingWapper orderShardingWapper = new OrderShardingWapper();

	private static long autotest_goodsOwnerId = ShenqiUserSet.autotest_goodsOwnerId;
	private static long proxyFissionGoodsOwnerId = ShenqiUserSet.proxyFissionGoodsOwnerId;
	private static long virtualCoinGoodsOwnerId = ShenqiUserSet.virtualCoinGoodsOwnerId;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("神器申请退货退款接口 - 已废弃");

		String accountid1;
		try {
			accountid1 = AccountCallServiceV2.getAccountId(20238699);
			AccountCallServiceV2.resetAccount(accountid1, new BigDecimal(
					9000000), new BigDecimal(0));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {

		applyRefundReq = new ConfirmApplyRefundReq();
		applySalesRefundCall = new ConfirmApplyRefundCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(applySalesRefundCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
		orderShardingWapper.activeDeadCommunicationsLink(orderShardingWapper);
	}

	private void buildVerifyData(OrderPo orderPo,
			BigDecimal productRefundAmount, BigDecimal taxRefundAmount,
			BigDecimal freightRefundAmount, Integer refundCount,
			String catalogId, Boolean isAllRefunded, String currency) {

		Long orderId = orderPo.getOrderId();

		RefundBillPo expectedRefundBillPo = new RefundBillPo();

		BigDecimal totalAmount = productRefundAmount.add(taxRefundAmount).add(
				freightRefundAmount);

		expectedRefundBillPo.setCatalogId(applyRefundReq.getCatalogId());
		expectedRefundBillPo.setTotalAmount(totalAmount);
		expectedRefundBillPo.setProductCount(applyRefundReq.getProductCount());

		expectedRefundBillPo
				.setFreight(freightRefundAmount);
		expectedRefundBillPo.setThirdpartyAmount(totalAmount);

		expectedRefundBillPo.setOrderId(applyRefundReq.getOrderId());
		expectedRefundBillPo.setUserId(orderPo.getUserId());
		expectedRefundBillPo.setSellerId(applyRefundReq.getSellerId());
		expectedRefundBillPo.setTopspeedRefund(false);
		expectedRefundBillPo.setAfterReceiving(false);
		expectedRefundBillPo.setRefundStatus(1);

		expectedRefundBillPo.setRefundBillStatus(10);

		// expectedRefundBillPo.setFailReason(failReason);
		// expectedRefundBillPo.setFailCode(failCode);
		expectedRefundBillPo.setTax(taxRefundAmount);
		expectedRefundBillPo.setProductAmount(productRefundAmount);
		
		List<RefundBillPo> refundBillList = orderShardingWapper.selectRefundBillListByOrderId(orderId);
		
		RefundBillPo actualRefundBillPo = refundBillList
				.stream()
				.filter(refundBillPo -> refundBillPo.getCatalogId().equalsIgnoreCase(catalogId))
				.collect(Collectors.toList()).get(0);

		RefundService.verifyRefundBillDb(expectedRefundBillPo,
				actualRefundBillPo);
		
		BigDecimal realSubmitAmount = null;
		
		UserRefundFundDetailPo expectedUserRefundFundDetailPo = new UserRefundFundDetailPo();

		expectedUserRefundFundDetailPo.setOrderId(orderId);
		expectedUserRefundFundDetailPo.setBizNo(isAllRefunded ? orderId
				.toString() : actualRefundBillPo.getRefundBillNo());
		expectedUserRefundFundDetailPo.setAccountAmount(BigDecimal.ZERO);
		expectedUserRefundFundDetailPo.setThirdpartyDiscount(BigDecimal.ZERO);
		expectedUserRefundFundDetailPo.setPaymentId(orderPo.getPaymentId());
		expectedUserRefundFundDetailPo.setAccountRefundStatus(-1);
		expectedUserRefundFundDetailPo.setThirdpartyRefundStatus(4);
		expectedUserRefundFundDetailPo.setRetryTimes(0);
		expectedUserRefundFundDetailPo.setMemo("0");
		expectedUserRefundFundDetailPo.setRebateAmount(BigDecimal.ZERO);
		expectedUserRefundFundDetailPo.setIsShenqi(true);
		
		List<UserRefundFundDetailPo> userRefundFundDetailList = orderShardingWapper
				.selectUserRefundFundDetailListByPaymentId(orderPo
						.getPaymentId());
		
		if (null != currency) {
			
			PaymentPo paymentPo = orderShardingWapper.selectPaymentById(orderPo.getPaymentId());
			
			if (currency.equalsIgnoreCase("CNY")
					&& paymentPo.getGatewayPayType().equalsIgnoreCase("6010"))
				realSubmitAmount = paymentPo.getRealSubmitRmbAmount();
			else
				// 如果这个退款单退了所有的商品
				if (isAllRefunded && userRefundFundDetailList.size() == 1)
					realSubmitAmount = paymentPo.getRealSubmitForeignAmount();
				else
					realSubmitAmount = totalAmount.multiply(
							paymentPo.getRmbVsRealSubmitForeignRate()).setScale(2,
							BigDecimal.ROUND_DOWN);
		}
		
		expectedUserRefundFundDetailPo
				.setThirdpartyAmount(realSubmitAmount == null ? totalAmount
						: realSubmitAmount);
		
		UserRefundFundDetailPo actualUserRefundFundDetailPo = new UserRefundFundDetailPo();

		if (null == applyRefundReq.getCatalogId()
				&& null == applyRefundReq.getProductCount()) {

			actualUserRefundFundDetailPo = userRefundFundDetailList
					.stream()
					.filter(po -> po.getBizNo().equalsIgnoreCase(
							String.valueOf(applyRefundReq.getOrderId())))
					.collect(Collectors.toList()).get(0);

			expectedUserRefundFundDetailPo.setBizType(1);
			
		} else {

			actualUserRefundFundDetailPo = userRefundFundDetailList
					.stream()
					.filter(po -> po.getBizNo().equalsIgnoreCase(
							actualRefundBillPo.getRefundBillNo()))
					.collect(Collectors.toList()).get(0);

			expectedUserRefundFundDetailPo.setBizType(1);
		}
		
		RefundService.verifyUserRefundFundDetailDb(
				expectedUserRefundFundDetailPo, actualUserRefundFundDetailPo);
	}

	/**
	 * 
	 * @param userId
	 * @param isDelivered
	 * @param currency (特殊情况时，提交给网关的币种)
	 */
	private void verify(Long userId, Boolean isDelivered, String currency) {

		OrderPo orderPo = orderShardingWapper
				.selectOrderbyOrderId(applyRefundReq.getOrderId());
		String catalogId = applyRefundReq.getCatalogId();

		List<OrderDetailPo> orderDetailPoList = orderShardingWapper
				.selectOrderDetailbyOrderId(applyRefundReq.getOrderId());

		Boolean isAllRefunded = RefundService.isAllRefunded(
				orderPo.getOrderId(), orderDetailPoList);

		if (null == catalogId) {

			for (OrderDetailPo orderDetailPo : orderDetailPoList) {
			
				this.buildVerifyData(orderPo, RefundService
						.getOrderDetailPaidAmountExcludeFreight(orderDetailPo,
								orderDetailPo.getProductCount(), true), RefundService
						.getOrderDetailTaxFeeAmount(orderDetailPo,
								orderDetailPo.getProductCount()), RefundService
						.getMaxCanRefundFreight(orderDetailPo,
								orderDetailPo.getFreight()), orderDetailPo
						.getProductCount(), orderDetailPo.getCatalogId(),
						isAllRefunded, currency);
			}
		} else {

			this.buildVerifyData(orderPo,
					applyRefundReq.getProductRefundAmount(),
					applyRefundReq.getTaxRefundAmount(),
					applyRefundReq.getFreightRefundAmount(),
					applyRefundReq.getProductCount(), catalogId, isAllRefunded, currency);
		}

		if (isAllRefunded) {

			Logger.comment("如果是全部退款并且没有发货，订单为取消状态");

			if (!isDelivered) {
				Logger.verifyEquals(13, orderPo.getOrderStatus(),
						"验证OrderStatus");

				Logger.verifyEquals("货或款全部退完，订单自动取消",
						orderPo.getCancelReason(), "验证CancelReason");
			}
			
			Logger.verifyEquals(2, orderPo.getReturnProductStatus(), "验证ReturnProductStatus");
		} else {
			
			Logger.verifyEquals(1, orderPo.getReturnProductStatus(), "验证ReturnProductStatus");
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_001() {
		Logger.start(true, "直销商退全部商品金额、运费、税费，hipopay已支付，申请退货退款成功");
		try {

			Integer mchId = DGSQBaseService.createIndependenceMch("USA");
			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createRetailShopProxychain(mchId, BigDecimal.TEN, false);

			Long shopId = productBean.getSellerId(); 
			
			GodPointsService.saveCreditPolicyReq((long)shopId);
			Thread.sleep(500);
			
			GodPointsService.sendCredit((long)shopId, 20238699L);
			Thread.sleep(500);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithIntegral(productBean, (long) mchId, 20L);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			String catalogId = orderDetailPoList.get(0).getCatalogId();
			int productCount = orderDetailPoList.get(0).getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, (long)mchId,
							catalogId, productCount);

			applyRefundReq.setSellerId((long)mchId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_002() {
		Logger.start(false, "申请退货退款,订单号不存在");
		try {

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(11111L);
			applyRefundReq.setCatalogId("c123456");
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(BigDecimal.ONE);
			applyRefundReq.setFreightRefundAmount(BigDecimal.ONE);
			applyRefundReq.setTaxRefundAmount(BigDecimal.ONE);

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ErrOrderNotExists",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("订单不存在", applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_004() {
		Logger.start(true, "直销商发货后,部分退款");
		try {

			Integer mchId = DGSQBaseService.createIndependenceMch("USA");
			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createRetailShopProxychain(mchId, BigDecimal.TEN, false);

			Long shopId = productBean.getSellerId(); 
			
			GodPointsService.saveCreditPolicyReq((long)shopId);
			Thread.sleep(500);
			
			GodPointsService.sendCredit((long)shopId, 20238699L);
			Thread.sleep(500);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithIntegral(productBean, (long) mchId, 20L);

			Order order = placeOrderResp.getOrderList().get(0);
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();
			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(mchId, orderId);

			String catalogId = orderDetailPoList.get(0).getCatalogId();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, (long)mchId, catalogId, 1);

			applyRefundReq.setSellerId((long)mchId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, true, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_005() {
		Logger.start(true, "同一退款单,退款中，重复申请退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.orderApplyRefund(productBean);

			Order order = placeOrderResp.getOrderList().get(0);

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();

			long orderId = order.getOrderId();
			String catalogId = orderDetailPoList.get(0).getCatalogId();

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(BigDecimal.ONE);
			applyRefundReq.setFreightRefundAmount(BigDecimal.ONE);
			applyRefundReq.setTaxRefundAmount(BigDecimal.ONE);

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Thread.sleep(2000);

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ILLEGAL_ARGUMENT",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("退款金额大于可退金额",
							applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_006() {
		Logger.start(true, "同一退款单,退款完成，重复申请退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.orderRefundSuccess(productBean);

			Order order = placeOrderResp.getOrderList().get(0);

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();

			long orderId = order.getOrderId();
			String catalogId = orderDetailPoList.get(0).getCatalogId();

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(BigDecimal.ONE);
			applyRefundReq.setFreightRefundAmount(BigDecimal.ONE);
			applyRefundReq.setTaxRefundAmount(BigDecimal.ONE);

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Thread.sleep(2000);

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ILLEGAL_ARGUMENT",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("退款金额大于可退金额", applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_007() {
		Logger.start(true, "申请的商品可退金额过大");

		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);

			String catalogId = orderDetailPo.getCatalogId();
			int productCount = orderDetailPo.getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, sellerId, catalogId,
							productCount);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(map.get(
					"maxProductRefundAmount").add(BigDecimal.ONE));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ILLEGAL_ARGUMENT",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("退款金额大于可退金额", applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_008() {
		Logger.start(true, "申请的订单运费金额过大");

		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);

			String catalogId = orderDetailPo.getCatalogId();
			int productCount = orderDetailPo.getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, sellerId, catalogId,
							productCount);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight")
					.add(BigDecimal.ONE));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ILLEGAL_ARGUMENT",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("退款金额大于可退金额", applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_009() {
		Logger.start(true, "申请的订单税费金额过大");

		try {
			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);

			String catalogId = orderDetailPo.getCatalogId();
			int productCount = orderDetailPo.getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, sellerId, catalogId,
							productCount);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax").add(
					BigDecimal.ONE));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ILLEGAL_ARGUMENT",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("退款金额大于可退金额", applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_010() {
		Logger.start(true, "代理订单全部商品金额、运费、税费，hipopay已支付，申请退货退款成功");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 3, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, BigDecimal.TEN, autotest_goodsOwnerId, productBean.getCurrency());

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			String catalogId = orderDetailPoList.get(0).getCatalogId();
			int productCount = orderDetailPoList.get(0).getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							catalogId, productCount);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_011() {
		Logger.start(true, "代理订单发货后,部分退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 3, false,
							true);
			String currency = productBean.getCurrency();

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithAllPromotionAndCurrency(productBean,
							BigDecimal.TEN, autotest_goodsOwnerId, currency);

			Order order = placeOrderResp.getOrderList().get(0);
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(),
					currency);

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);
			
			// 卖家发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);
			TradingSyncService.getSyncResult(orderId);

			String catalogId = orderDetailPoList.get(1).getCatalogId();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							catalogId, 1);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight")
					.subtract(BigDecimal.ONE));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, true, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_012() {
		Logger.start(true, "代理订单未发货,部分退款,商品可退金额不正确,退款失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 3, false,
							true);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithAllPromotionAndCurrency(productBean,
							BigDecimal.TEN, autotest_goodsOwnerId,
							productBean.getCurrency());

			Order order = placeOrderResp.getOrderList().get(0);
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();
			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);

			String catalogId = orderDetailPoList.get(1).getCatalogId();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							catalogId, 1);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(map.get(
					"maxProductRefundAmount").add(BigDecimal.ONE));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight")
					.subtract(BigDecimal.ONE));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ILLEGAL_ARGUMENT",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("代理订单退款商品金额不正确", applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_013() {
		Logger.start(true, "代理订单未发货,部分退款,商品可退税费不正确,退款失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 3, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithAllPromotion(productBean, BigDecimal.TEN,
							autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();
			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);

			String catalogId = orderDetailPoList.get(1).getCatalogId();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							catalogId, 1);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight")
					.subtract(BigDecimal.ONE));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax").subtract(
					BigDecimal.ONE));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ILLEGAL_ARGUMENT",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("代理订单退款税费金额不正确", applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_014() {
		Logger.start(true, "分销小店订单全部商品金额、运费、税费，hipopay已支付，申请退货退款成功");
		try {

			Integer mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createIndependenceProxychain(mchId, 4, true, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, mchId);

			Order order = placeOrderResp.getOrderList().get(0);
			Long userId = placeOrderResp.getUserId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			String catalogId = orderDetailPoList.get(0).getCatalogId();
			int productCount = orderDetailPoList.get(0).getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, (long) mchId, catalogId,
							productCount);

			applyRefundReq.setSellerId((long) mchId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_015() {
		Logger.start(true, "分销小店订单未发货,部分退款");
		try {

			Integer mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createRetailShopProxychain(mchId, BigDecimal.TEN, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithAllPromotion(productBean, BigDecimal.ZERO,
							mchId);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();
			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());
			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(mchId, orderId);

			String catalogId = orderDetailPoList.get(0).getCatalogId();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, (long) mchId, catalogId, 1);

			applyRefundReq.setSellerId((long)mchId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_016() {
		Logger.start(true, "代理订单未发货后,部分退款,商品可退金额不正确,退款失败");
		try {

			Integer mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createRetailShopProxychain(mchId, BigDecimal.TEN, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, mchId);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();
			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			String catalogId = orderDetailPoList.get(0).getCatalogId();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, (long) mchId, catalogId, 1);

			applyRefundReq.setSellerId((long) mchId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(map.get(
					"maxProductRefundAmount").add(BigDecimal.ONE));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight")
					.subtract(BigDecimal.ONE));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("代理订单退款商品金额不正确",
							applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_017() {
		Logger.start(true, "分销小店订单未发货,部分退款,商品可退税费不正确,退款失败");
		try {

			Integer mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createRetailShopProxychain(mchId, BigDecimal.TEN, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, mchId);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();
			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(mchId, orderId);

			String catalogId = orderDetailPoList.get(0).getCatalogId();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, (long) mchId, catalogId, 1);

			applyRefundReq.setSellerId((long) mchId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight")
					.subtract(BigDecimal.ONE));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax").subtract(
					BigDecimal.ONE));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ErrOrderAmountNotMatch",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("taxRefundAmount:退款税费金额必须大于等于0",
							applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_018() {
		Logger.start(true, "盛付通部分支付订单,退款失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();
			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6010");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), 6010);

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			String catalogId = orderDetailPoList.get(0).getCatalogId();

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(BigDecimal.ONE);
			applyRefundReq.setFreightRefundAmount(BigDecimal.ONE);
			applyRefundReq.setTaxRefundAmount(BigDecimal.ZERO);

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ERR_ORDER_CANCELLED",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("抱歉，该订单人民币收款暂不支持部分退款", applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_019() {
		Logger.start(true, "已取消订单,退款失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();
			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			SqTradingCallService.cancelOrder(orderId,
					CancelOrderTypeEnum.SELLER_CANCEL_ORDER,
					autotest_goodsOwnerId);

			String catalogId = orderDetailPoList.get(0).getCatalogId();

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(BigDecimal.ONE);
			applyRefundReq.setFreightRefundAmount(BigDecimal.ONE);
			applyRefundReq.setTaxRefundAmount(BigDecimal.ONE);

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ERR_ORDER_CANCELLED",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("当前状态不能退货退款", applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_020() {
		Logger.start(true, "支付超过90天,退款失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();
			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			OrderPo record = new OrderPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.DAY_OF_MONTH, -91);

			record.setOrderId(orderId);
			record.setPaidTime(calendar.getTime());

			orderShardingWapper.orderMapper.updateByPrimaryKeySelective(record);

			String catalogId = orderDetailPoList.get(0).getCatalogId();

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(BigDecimal.ONE);
			applyRefundReq.setFreightRefundAmount(BigDecimal.ONE);
			applyRefundReq.setTaxRefundAmount(BigDecimal.ONE);

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ERR_ORDER_CANCELLED",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("订单已支付超过90天无法发起退款",
							applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_021() {
		Logger.start(true, "分销已结算订单,退款失败");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false,
							false);
			long merchantId = productBean.getSellerId();
			Long userId = (long) new OrderCallService().createNewUser();

			List<Long> distributorList = SqDistributorService
					.buildSqDistributorRelation(productBean.getSellerId(), 0,
							2, 0);
			SqDistributorService.setDistributorConfig(merchantId, 1, false);
			SqDistributorService.bindDistributorConsumerRelation(userId,
					merchantId, distributorList.get(1));

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithUserId(productBean, userId);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(),
					productBean.getCurrency());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(5000);

			long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 接单
			TradingCallService
					.sellerAcceptOrder(autotest_goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);
			TradingSyncService.getSyncResult(orderId);

			ShenqiSettlementService.doSettlement();
			Thread.sleep(5000);

			// 代购神器分销订单结算
			SqDistributorService.doDistributorSettlement();
			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");

			String catalogId = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0).getCatalogId();
			
			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							catalogId, 1);
			
			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");
			Logger.verifyEquals(
					String.format("该订单因分销佣金已结算，无法退款",
							applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_022() {
		Logger.start(true, "神器订单，店主申请退货退款,退款失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 2, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();
			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			String catalogId = orderDetailPoList.get(0).getCatalogId();

			applyRefundReq.setSellerId(productBean.getSellerId());
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(BigDecimal.ONE);
			applyRefundReq.setFreightRefundAmount(BigDecimal.ONE);
			applyRefundReq.setTaxRefundAmount(BigDecimal.ONE);

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ERR_NO_PERMISSION",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("没有权限发起退款申请", applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_023() {
		Logger.start(true, "盛付通支持整单退款,退款成功");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6010");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), 6010);

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);
			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							null, null);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(null);
			applyRefundReq.setProductCount(null);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_024() {
		Logger.start(true, "主单拆单后的订单，盛付通支付不能发起全部退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6010");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), 6010);

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);
			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							null, null);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(null);
			applyRefundReq.setProductCount(null);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_026() {
		Logger.start(true, "虚拟库存订单，单个商品全部退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId, 2);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			String catalogId = orderDetailPoList.get(0).getCatalogId();
			int productCount = orderDetailPoList.get(0).getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							catalogId, productCount);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_027() {
		Logger.start(true, "虚拟库存订单，包含多个虚拟库存商品，单个商品全部退款");
		try {

			AgentProductBean productBean = new AgentProductBean();

			String productId = DGSQBaseService.createAgentProduct(
					(int) autotest_goodsOwnerId, "autotest_goodsOwnerId", true,
					"CNY", true);

			productBean.setSellerId(autotest_goodsOwnerId);
			productBean.setSellerLoginId(new DGUserWapper()
					.selectDGUserInfo((int) autotest_goodsOwnerId).get(0)
					.getLoginId());
			productBean.setProductId(productId);
			productBean.setRootProductId(productId);
			productBean.setCatalogList(DGSQBaseService
					.getCatalogIdList(productId));
			productBean.setRootCatalogList(DGSQBaseService
					.getCatalogIdList(productId));
			productBean.setGoodsOwnerId(autotest_goodsOwnerId);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeVStockOrder3(productBean);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			String catalogId = orderDetailPoList.get(0).getCatalogId();
			int productCount = orderDetailPoList.get(0).getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							catalogId, productCount);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_028() {
		Logger.start(true, "虚拟库存订单，包含一个虚拟库存商品，一个真实库存商品，虚拟商品全部退款");
		try {

			AgentProductBean productBean = new AgentProductBean();

			String productId = DGSQBaseService.createAgentProduct(
					(int) autotest_goodsOwnerId, "autotest_goodsOwnerId", true,
					"CNY", true);

			productBean.setSellerId(autotest_goodsOwnerId);
			productBean.setSellerLoginId(new DGUserWapper()
					.selectDGUserInfo((int) autotest_goodsOwnerId).get(0)
					.getLoginId());
			productBean.setProductId(productId);
			productBean.setRootProductId(productId);
			productBean.setCatalogList(DGSQBaseService
					.getCatalogIdList(productId));
			productBean.setRootCatalogList(DGSQBaseService
					.getCatalogIdList(productId));
			productBean.setGoodsOwnerId(autotest_goodsOwnerId);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeVStockOrder4(productBean);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			String catalogId = orderDetailPoList.get(0).getCatalogId();
			int productCount = orderDetailPoList.get(0).getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							catalogId, productCount);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_029() {
		Logger.start(true, "虚拟库存订单，包含多个虚拟库存商品，每个商品依次退款");
		try {

			AgentProductBean productBean = new AgentProductBean();

			String productId = DGSQBaseService.createAgentProduct(
					(int) autotest_goodsOwnerId, "autotest_goodsOwnerId", true,
					"CNY", true);

			productBean.setSellerId(autotest_goodsOwnerId);
			productBean.setSellerLoginId(new DGUserWapper()
					.selectDGUserInfo((int) autotest_goodsOwnerId).get(0)
					.getLoginId());
			productBean.setProductId(productId);
			productBean.setRootProductId(productId);
			productBean.setCatalogList(DGSQBaseService
					.getCatalogIdList(productId));
			productBean.setRootCatalogList(DGSQBaseService
					.getCatalogIdList(productId));
			productBean.setGoodsOwnerId(autotest_goodsOwnerId);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeVStockOrder3(productBean);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			for (OrderDetailPo orderDetailPo : orderDetailPoList) {

				String catalogId = orderDetailPo.getCatalogId();
				int productCount = orderDetailPo.getProductCount();

				HashMap<String, BigDecimal> map = RefundService
						.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
								catalogId, productCount);

				applyRefundReq.setSellerId(autotest_goodsOwnerId);
				applyRefundReq.setOrderId(orderId);
				applyRefundReq.setCatalogId(catalogId);
				applyRefundReq.setProductCount(productCount);
				applyRefundReq.setProductRefundAmount(map
						.get("maxProductRefundAmount"));
				applyRefundReq.setFreightRefundAmount(map
						.get("maxRefundFreight"));
				applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

				applySalesRefundCall.setData(applyRefundReq);
				applySalesRefundCall.callService();

				// 退款提交到网关
				UserRefundFundDetailPo record = new UserRefundFundDetailPo();

				Calendar calendar = Calendar.getInstance();
				calendar.setTime(new Date());
				calendar.add(Calendar.MINUTE, -6);

				record.setPaymentId(paymentId);
				record.setUpdateTime(calendar.getTime());

				orderShardingWapper.userRefundFundDetailMapper
						.updateByPrimaryKeySelective(record);

				RefundService.supplementRefund(orderId);

				// 支付网关退款回调
				SQPayGateWayCallService.refundNotifyCall("13",
						paymentId.toString(), userId.intValue());

				Logger.comment("userId: " + userId + ", orderId: " + orderId);
				Logger.verifyEquals("true",
						applySalesRefundCall.getString("success"), "验证success");

				this.verify(userId, false, null);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_030() {
		Logger.start(true, "外币标价商品，盛付通支付,退款成功");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							true);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, null, 2, autotest_goodsOwnerId,
							productBean.getCurrency());

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6010");

			// 根据人民币离岸汇率计算
			BigDecimal exchangeRmbRateForTe = DGSQBaseService
					.getCurrencyConfig(productBean.getCurrency())
					.getExchangeRmbRateForTe();

			// 支付网关支付回调交易
			SQPayGateWayCallService
					.DGSQNotifyCall(
							String.valueOf(thirdTradingId),
							amount.subtract(BigDecimal.ZERO)
									.multiply(exchangeRmbRateForTe)
									.setScale(2, BigDecimal.ROUND_HALF_DOWN)
									.toString(), userId.intValue(),
							BigDecimal.ZERO.toPlainString(), 6010);

			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);
			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							null, null);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(null);
			applyRefundReq.setProductCount(null);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, "CNY");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_031() {
		Logger.start(true, "人民币标价商品，商户不允许收取人民币，hipopay支付,整单退款成功");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) 500956988, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, null, 1, 500956988L,
							productBean.getCurrency());
			
			String currency = "USD";

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6000");

			// 根据人民币离岸汇率计算
			BigDecimal exchangeRmbRate = DGSQBaseService.getCurrencyConfig(
					"USD").getExchangeRmbRate();

			amount = amount.multiply(
					BigDecimal.ONE.divide(exchangeRmbRate, 7,
							BigDecimal.ROUND_UP)).setScale(2,
					BigDecimal.ROUND_UP);

			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(),
					currency, currency);

			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);
			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, 500956988L,
							null, null);

			applyRefundReq.setSellerId(500956988L);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(null);
			applyRefundReq.setProductCount(null);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, currency);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_032() {
		Logger.start(true, "人民币标价商品，商户不允许收取人民币，hipopay支付,部分退款成功");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) 500956988, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, null, 1, 500956988L,
							productBean.getCurrency());
			
			String currency = "USD";

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();
			String catalogId = order.getOrderDetailPoList().get(0).getCatalogId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6000");

			// 根据人民币离岸汇率计算
			BigDecimal exchangeRmbRate = DGSQBaseService.getCurrencyConfig(
					"USD").getExchangeRmbRate();

			amount = amount.multiply(
					BigDecimal.ONE.divide(exchangeRmbRate, 7,
							BigDecimal.ROUND_UP)).setScale(2,
					BigDecimal.ROUND_UP);

			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(),
					currency, currency);

			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);
			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, 500956988L,
							catalogId, 1);

			applyRefundReq.setSellerId(500956988L);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, currency);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_033() {
		Logger.start(true, "直销商退费金额为0，hipopay已支付，申请退货退款失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			String catalogId = orderDetailPoList.get(0).getCatalogId();
			int productCount = orderDetailPoList.get(0).getProductCount();

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(BigDecimal.ZERO);
			applyRefundReq.setFreightRefundAmount(BigDecimal.ZERO);
			applyRefundReq.setTaxRefundAmount(BigDecimal.ZERO);

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();
			
			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ILLEGAL_ARGUMENT",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("退款金额不能为0", applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_034() {
		Logger.start(true, "直销商退费金额为负数，hipopay已支付，申请退货退款失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			String catalogId = orderDetailPoList.get(0).getCatalogId();
			int productCount = orderDetailPoList.get(0).getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							catalogId, productCount);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(BigDecimal.ONE.negate());
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();
			
			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ILLEGAL_ARGUMENT",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("productRefundAmount:退款商品金额必须大于等于0", applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_035() {
		Logger.start(true, "商户余额不足，结算单状态为3，申请退货退款失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, true);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderNegativeProfit(productBean, BigDecimal.ZERO,
							autotest_goodsOwnerId, productBean.getCurrency(),
							null, null);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);
			
			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);

			// 代购神器结算
			ShenqiSettlementService.doSettlement();

			String catalogId = orderDetailPoList.get(0).getCatalogId();
			int productCount = orderDetailPoList.get(0).getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							catalogId, productCount);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(map.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();
			
			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals(
					String.format("暂不支持的结算状态", applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_036() {
		Logger.start(true, "申请的订单运费为负数");

		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);

			String catalogId = orderDetailPo.getCatalogId();
			int productCount = orderDetailPo.getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, sellerId, catalogId,
							productCount);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(BigDecimal.ONE.negate());
			applyRefundReq.setTaxRefundAmount(BigDecimal.ONE);

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ILLEGAL_ARGUMENT",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("freightRefundAmount:退款运费金额必须大于等于0", applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_037() {
		Logger.start(true, "申请的订单税费为负数");

		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			OrderDetailPo orderDetailPo = order.getOrderDetailPoList().get(0);

			String catalogId = orderDetailPo.getCatalogId();
			int productCount = orderDetailPo.getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, sellerId, catalogId,
							productCount);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(BigDecimal.ONE);
			applyRefundReq.setTaxRefundAmount(BigDecimal.ONE.negate());

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");

			Logger.verifyEquals("ILLEGAL_ARGUMENT",
					applySalesRefundCall.getString("errorCode"), "验证返回码");

			Logger.verifyEquals(
					String.format("taxRefundAmount:退款税费金额必须大于等于0", applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_038() {
		Logger.start(true, "直销商发货后,整单退款，不需要取消订单");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();
			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							null, null);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(null);
			applyRefundReq.setProductCount(null);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, true, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_039() {
		Logger.start(true, "直销商发货后,全部退货退款, 不需要取消订单");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();
			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId, null, null);

			String catalogId = orderDetailPoList.get(0).getCatalogId();
			Integer refundedCount = orderDetailPoList.get(0).getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, sellerId, catalogId, refundedCount);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(refundedCount);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, true, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_040() {
		Logger.start(true, "人民币标价商品，商户不允许收取人民币，hipopay支付,商品依次退货退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) 500956988, 0, false,
							false);
			
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithAllPromotionAndCurrency(productBean, null,
							500956988L, productBean.getCurrency());
			
			String currency = "USD";

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6000");

			// 根据人民币离岸汇率计算
			BigDecimal exchangeRmbRate = DGSQBaseService.getCurrencyConfig(
					"USD").getExchangeRmbRate();

			amount = amount.multiply(
					BigDecimal.ONE.divide(exchangeRmbRate, 7,
							BigDecimal.ROUND_UP)).setScale(2,
					BigDecimal.ROUND_UP);

			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(),
					currency, currency);

			TradingSyncService.getSyncResult(orderId);

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);
			
			for (int i = 0; i < order.getOrderDetailPoList().size(); i++) {
				
				String catalogId = order.getOrderDetailPoList().get(i).getCatalogId();
				Integer refundedCount = order.getOrderDetailPoList().get(i).getProductCount();
				
				HashMap<String, BigDecimal> map = RefundService
						.getShenqiRefundAmount(orderId, 500956988L,
								catalogId, refundedCount);

				applyRefundReq.setSellerId(500956988L);
				applyRefundReq.setOrderId(orderId);
				applyRefundReq.setCatalogId(catalogId);
				applyRefundReq.setProductCount(refundedCount);
				applyRefundReq.setProductRefundAmount(map
						.get("maxProductRefundAmount"));
				applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
				applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

				applySalesRefundCall.setData(applyRefundReq);
				applySalesRefundCall.callService();

				// 退款提交到网关
				UserRefundFundDetailPo record = new UserRefundFundDetailPo();

				Calendar calendar = Calendar.getInstance();
				calendar.setTime(new Date());
				calendar.add(Calendar.MINUTE, -6);

				record.setPaymentId(paymentId);
				record.setUpdateTime(calendar.getTime());

				orderShardingWapper.userRefundFundDetailMapper
						.updateByPrimaryKeySelective(record);

				RefundService.supplementRefund(orderId);

				// 支付网关退款回调
				SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
						userId.intValue());

				Logger.comment("userId: " + userId + ", orderId: " + orderId);
				Logger.verifyEquals("true",
						applySalesRefundCall.getString("success"), "验证success");

				this.verify(userId, false, currency);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_041() {
		Logger.start(true, "直销商带有服务费率退全部商品金额、运费、税费，hipopay已支付，申请退货退款成功");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithServiceRate(productBean);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			String catalogId = orderDetailPoList.get(0).getCatalogId();
			int productCount = orderDetailPoList.get(0).getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							catalogId, productCount);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_042() {
		Logger.start(true, "直销商带有服务费率整单退款，hipopay已支付，申请退货退款成功");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithServiceRate(productBean);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			long orderId = order.getOrderId();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							null, null);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(null);
			applyRefundReq.setProductCount(null);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_043() {
		Logger.start(true, "分销已结算订单,整单退款失败");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false,
							false);
			long merchantId = productBean.getSellerId();
			Long userId = (long) new OrderCallService().createNewUser();

			List<Long> distributorList = SqDistributorService
					.buildSqDistributorRelation(productBean.getSellerId(), 0,
							2, 0);
			SqDistributorService.setDistributorConfig(merchantId, 1, false);
			SqDistributorService.bindDistributorConsumerRelation(userId,
					merchantId, distributorList.get(1));

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithUserId(productBean, userId);

			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(),
					productBean.getCurrency());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(5000);

			long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 接单
			TradingCallService
					.sellerAcceptOrder(autotest_goodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);
			TradingSyncService.getSyncResult(orderId);

			ShenqiSettlementService.doSettlement();
			Thread.sleep(5000);

			// 代购神器分销订单结算
			SqDistributorService.doDistributorSettlement();
			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");
			
			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							null, null);
			
			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(null);
			applyRefundReq.setProductCount(null);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");
			Logger.verifyEquals(
					String.format("该订单因分销佣金已结算，无法退款,orderId:%s",
							applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_044() {
		Logger.start(true, "代理裂变已结算订单,整单退款失败");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createPromotersProxychain((int) proxyFissionGoodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, proxyFissionGoodsOwnerId);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), productBean.getCurrency());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(5000);

			long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 接单
			TradingCallService
					.sellerAcceptOrder(proxyFissionGoodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 发货
			SqTradingCallService.delivery(proxyFissionGoodsOwnerId, orderId,
					null, null);
			TradingSyncService.getSyncResult(orderId);

			ShenqiSettlementService.doSettlement();
			Thread.sleep(5000);

			// 代理裂变订单结算
			ShenqiSettlementService.executeProxyFissionSettlementTask();
			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");
			
			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, proxyFissionGoodsOwnerId,
							null, null);
			
			applyRefundReq.setSellerId(proxyFissionGoodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(null);
			applyRefundReq.setProductCount(null);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");
			Logger.verifyEquals(
					String.format("该订单因分销佣金已结算，无法退款,orderId:%s",
							applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_045() {
		Logger.start(true, "代理裂变已结算订单,部分退款失败");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createPromotersProxychain((int) proxyFissionGoodsOwnerId, 1, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, proxyFissionGoodsOwnerId);

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			String catalogId = placeOrderResp.getOrderList().get(0).getOrderDetailPoList().get(0).getCatalogId();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), productBean.getCurrency());

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(5000);

			long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 接单
			TradingCallService
					.sellerAcceptOrder(proxyFissionGoodsOwnerId, orderId);
			TradingSyncService.getSyncResult(orderId);

			// 发货
			SqTradingCallService.delivery(proxyFissionGoodsOwnerId, orderId,
					null, null);
			TradingSyncService.getSyncResult(orderId);

			ShenqiSettlementService.doSettlement();
			Thread.sleep(5000);

			// 代理裂变订单结算
			ShenqiSettlementService.executeProxyFissionSettlementTask();
			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");
			
			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, proxyFissionGoodsOwnerId,
							catalogId, 1);
			
			applyRefundReq.setSellerId(proxyFissionGoodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			Logger.verifyEquals("false",
					applySalesRefundCall.getString("success"), "验证success");
			Logger.verifyEquals(
					String.format("该订单因代理佣金已结算，无法退款",
							applyRefundReq.getOrderId()),
					applySalesRefundCall.getString("errorMessage"),
					"验证errorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_046() {
		Logger.start(true, "代理订单发货后，多个商品，代理0利润，部分退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false);
			String currency = productBean.getCurrency();

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderZeroProfit(productBean, autotest_goodsOwnerId,
							currency, 1);

			Order order = placeOrderResp.getOrderList().get(0);
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = order
					.getOrderDetailPoList();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(),
					currency);

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);
			TradingSyncService.getSyncResult(orderId);
			
			// 卖家发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);
			TradingSyncService.getSyncResult(orderId);

			String catalogId = orderDetailPoList.get(1).getCatalogId();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, autotest_goodsOwnerId,
							catalogId, 1);

			applyRefundReq.setSellerId(autotest_goodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(1);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight")
					.subtract(BigDecimal.ONE));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, true, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_ConfirmApplyRefund_047() {
		Logger.start(true, "代购神器，直销商，连锁店模式，已接单，已结算, 申请退货退款成功");
		try {

			// 创建订单
			Logger.comment("前置数据准备");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain(ShenqiUserSet.chainStoreGoodsOwnerId.intValue(), 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeChainStoreOrder(productBean, ShenqiUserSet.chainStoreGoodsOwnerId,
							productBean.getCurrency());

			Long userId = placeOrderResp.getUserId();
			long orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			BigDecimal totalPrice = placeOrderResp.getPayableAmount();
			
			// 第一个订单下的商品列表
			List<OrderDetailPo> orderDetailPoList = placeOrderResp
					.getOrderList().get(0).getOrderDetailPoList();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "501476063", "6401");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), 6401);

			TradingSyncService.getSyncResult(orderId);
			Thread.sleep(5000);

			Logger.comment("前置数据准备结束");

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			String catalogId = orderDetailPoList.get(0).getCatalogId();
			int productCount = orderDetailPoList.get(0).getProductCount();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, ShenqiUserSet.chainStoreGoodsOwnerId,
							catalogId, productCount);

			applyRefundReq.setSellerId(ShenqiUserSet.chainStoreGoodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(catalogId);
			applyRefundReq.setProductCount(productCount);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ConfirmApplyRefund_048() {
		Logger.start(true, "直销商带有服务费率整单退款，hipopay已支付，申请退货退款成功");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createIndependenceProxychain((int)virtualCoinGoodsOwnerId, 1, false, false);
			
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithUserIdAndSalemanAndGoodsOwnerIdAndIntegral(
							productBean, productBean.getSellerId(), null,
							virtualCoinGoodsOwnerId, null);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal useAccountAmount = placeOrderResp.getPayableAmount();
			Long tradingId = placeOrderResp.getTradingId();
			
			// 充值代币
			SqPretradeService.virtualCoinCharge(virtualCoinGoodsOwnerId,
					productBean.getSellerId(), useAccountAmount);

			// 支付订单
			SqTradingCallService.payOrderWithVirtualCoin(userId, tradingId, useAccountAmount);

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			HashMap<String, BigDecimal> map = RefundService
					.getShenqiRefundAmount(orderId, virtualCoinGoodsOwnerId,
							null, null);

			applyRefundReq.setSellerId(virtualCoinGoodsOwnerId);
			applyRefundReq.setOrderId(orderId);
			applyRefundReq.setCatalogId(null);
			applyRefundReq.setProductCount(null);
			applyRefundReq.setProductRefundAmount(map
					.get("maxProductRefundAmount"));
			applyRefundReq.setFreightRefundAmount(map.get("maxRefundFreight"));
			applyRefundReq.setTaxRefundAmount(map.get("maxRefundTax"));

			applySalesRefundCall.setData(applyRefundReq);
			applySalesRefundCall.callService();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13", paymentId.toString(),
					userId.intValue());

			Logger.comment("userId: " + userId + ", orderId: " + orderId);
			Logger.verifyEquals("true",
					applySalesRefundCall.getString("success"), "验证success");

			this.verify(userId, false, null);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	public static void main(String[] args) throws ClientProtocolException,
			IOException {

		Ts_ConfirmApplyRefund test = new Ts_ConfirmApplyRefund();

		applyRefundReq = new ConfirmApplyRefundReq();

		applyRefundReq.setOrderId(1560032705L);
		applyRefundReq.setSellerId(500956988L);
//		applyRefundReq.setCatalogId("c7308597");
//		applyRefundReq.setProductCount(null);
		applyRefundReq.setProductRefundAmount(new BigDecimal("2590.00"));
		applyRefundReq.setTaxRefundAmount(new BigDecimal("0"));
		applyRefundReq.setFreightRefundAmount(new BigDecimal("28.00"));

		test.verify(25762705L, false, null);
	}
}
